package net.crowdloud.server.DatabaseAccess.user;

import java.util.ArrayList;

import javax.jdo.PersistenceManager;

import net.crowdloud.server.DatabaseAccess.problem.Problem;
import net.crowdloud.server.DatabaseAccess.solution.Solution;

public class SaveUser {

	public static void addNew(PersistenceManager persistenceManager,
			net.crowdloud.shared.entities.User user, String tags) {

		User userDatabase = ConvertUserToDatabase.getDatabaseUser(new User(),
				user, tags);

		userDatabase.setUserProblems(new ArrayList<Problem>());
		userDatabase.setUserSolutions(new ArrayList<Solution>());

		persistenceManager.makePersistent(userDatabase);
	}

	public static void update(PersistenceManager persistenceManager,
			net.crowdloud.shared.entities.User user, String tags) {

		User userDatabase = GetUser.getUserDatabase(persistenceManager,
				user.getUserID());

		persistenceManager.makePersistent(ConvertUserToDatabase
				.getDatabaseUser(userDatabase, user, tags));
	}
}